//
//  MYGFindSendImageCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/19.
//

import UIKit

class MYGFindSendImageCell: UICollectionViewCell {
    // MARK: - Proprety
    var model: MYGFindSendImageCellModel? {
        didSet {
            guard let model = model else {
                return
            }
            
            if model.isAdd {
                imageButton.setImage(UIImage(named: "Find/add_image"), for: .normal)
            } else {
                imageButton.setImage(model.image, for: .normal)
            }
            
            closeButton.isHidden = model.isAdd
        }
    }
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        contentView.addSubviews([imageButton, closeButton])
        
        imageButton.snp.makeConstraints { make in
            make.left.bottom.equalToSuperview()
            make.width.height.equalTo(90)
        }
        
        closeButton.snp.makeConstraints { make in
            make.right.top.equalToSuperview()
            make.width.height.equalTo(12)
        }
    }
    
    // MARK: - lazy load
    private lazy var imageButton: UIButton = {
        let btn = UIButton()
        btn.contentHorizontalAlignment = .fill
        btn.contentVerticalAlignment = .fill

        btn.isUserInteractionEnabled = false
        return btn
    }()
    
    private lazy var closeButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "Find/close"), for: .normal)
        btn.addTarget(self, action: #selector(close), for: .touchUpInside)
        return btn
    }()
    
    @objc
    private func close() {
        self.model?.removeAction?()
    }
}
